package org.coody.czone.common.jdbc;

import org.coody.framework.core.annotation.AutoBuild;
import org.coody.framework.core.bean.InitBeanFace;
import org.coody.framework.core.build.ConfigBuilder;
import org.coody.framework.core.util.StringUtil;
import org.coody.framework.jdbc.JdbcHandle;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

@AutoBuild
public class JdbcTemplate extends JdbcHandle implements InitBeanFace{


	public void init() throws Exception {
			ConfigBuilder configBuilder=new ConfigBuilder("config");
			configBuilder.build();
			HikariConfig config = new HikariConfig();
			config.setJdbcUrl(System.getProperty("jdbc.url"));
			config.setUsername(System.getProperty("jdbc.user"));
			config.setPassword(System.getProperty("jdbc.password"));
			config.setDriverClassName(System.getProperty("jdbc.driverClass"));
			config.addDataSourceProperty("cachePrepStmts", true);
			config.addDataSourceProperty("prepStmtCacheSize", 500);
			config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
			config.setConnectionTestQuery("SELECT 1");
			config.setMinimumIdle(StringUtil.toInteger(System.getProperty("jdbc.minimumIdle")));
			config.setMaximumPoolSize(StringUtil.toInteger(System.getProperty("jdbc.maximumPoolSize")));
			this.dataSource= new HikariDataSource(config);
	}

}
